﻿Imports Microsoft.Xna.Framework

Namespace Global.Runa.Resources.ContentReader.VectorFont

    Public Class VectorFont

#Region "struct KerningPair"

        ''' <summary>Pair of characters for kerning informations</summary>
        Public Structure KerningPair

            ''' <summary>Initializes a new kerning pair</summary>
            ''' <param name="left">Left character of the kerning pair</param>
            ''' <param name="right">Right character of the kerning pair</param>
            Public Sub New(left As Char, right As Char)
                Me.Left = left
                Me.Right = right
            End Sub

            ''' <summary>The left character in the kerning pair</summary>
            Public Left As Char
            ''' <summary>The right character in the kerning pair</summary>
            Public Right As Char

            ''' <summary>Returns a hash code for the kerning pair</summary>
            ''' <returns>A hash code for the kerning pair</returns>
            Public Overrides Function GetHashCode() As Integer
                Return (AscW(Me.Left)) * 65536 + (AscW(Me.Right))
            End Function

            ''' <summary>Compares this object to another object</summary>
            ''' <param name="other">Object to compare to</param>
            ''' <returns>True if both objects are identical</returns>
            Public Overrides Function Equals(other As Object) As Boolean
                If Not (TypeOf other Is KerningPair) Then
                    Return False
                End If

                Dim kerningPair As KerningPair = CType(other, KerningPair)

                Return (kerningPair.Left = Me.Left) AndAlso (kerningPair.Right = Me.Right)
            End Function

        End Structure

#End Region

        ''' <summary>Constructs a new vector font</summary>
        ''' <param name="lineHeight">
        '''   Height of a single line of text in this font
        ''' </param>
        ''' <param name="characters">List of Characters contained in the font</param>
        ''' <param name="characterMap">
        '''   Map used to associate unicode characters with character indices
        ''' </param>
        ''' <param name="kerningTable">
        '''   Kerning data for adjusting the space between specific characters
        ''' </param>
        Public Sub New(lineHeight As Single, characters As List(Of VectorFontCharacter), characterMap As Dictionary(Of Char, Integer), kerningTable As Dictionary(Of VectorFont.KerningPair, Vector2))
            Me.m_lineHeight = lineHeight
            Me.m_characters = characters
            Me.m_characterMap = characterMap
            Me.m_kerningTable = kerningTable
        End Sub

        ' ''' <summary>Constructs the outline of the specified string</summary>
        ' ''' <param name="text">String to construct an outline of</param>
        ' ''' <returns>The outline of the specified string</returns>
        'Public Function Outline(text As String) As OutlinedText
        '    Return New OutlinedText(Me, text)
        'End Function

        ''' <summary>Constructs a mesh of the strings face plane</summary>
        ''' <param name="text">Text to construct a flat polygon mesh of</param>
        ''' <returns>The filled string mesh</returns>
        Public Function Fill(text As String) As FilledText
            Return New FilledText(Me, text)
        End Function

        ' ''' <summary>Constructs an extruded polygon mesh of the string</summary>
        ' ''' <param name="text">String from which to construct a polygon mesh</param>
        ' ''' <returns>The extruded string mesh</returns>
        'Public Function Extrude(text As String) As ExtrudedText
        '    Return New ExtrudedText(Me, text)
        'End Function

        ''' <summary>Height of a single line of text in this font</summary>
        Public ReadOnly Property LineHeight() As Single
            Get
                Return Me.m_lineHeight
            End Get
        End Property

        ''' <summary>List of the characters contained in this font</summary>
        Public ReadOnly Property Characters() As List(Of VectorFontCharacter)
            Get
                Return Me.m_characters
            End Get
        End Property

        ''' <summary>Maps unicode character to indices into the character list</summary>
        Public ReadOnly Property CharacterMap() As Dictionary(Of Char, Integer)
            Get
                Return Me.m_characterMap
            End Get
        End Property

        ''' <summary>
        '''   Kerning table for adjusting the positions of specific character combinations
        ''' </summary>
        ''' <remarks>
        '''   Certain character combination, such as the two consecutive characters 'AV'
        '''   have diagonal shapes that would cause the characters to visually appear
        '''   is if they were further apart from each other. Kerning adjusts the distances
        '''   between such characters to keep the perceived character distance at the
        '''   same level for all character combinations.
        ''' </remarks>
        Public ReadOnly Property KerningTable() As Dictionary(Of VectorFont.KerningPair, Vector2)
            Get
                Return Me.m_kerningTable
            End Get
        End Property

        ''' <summary>Height of a single line of text in this font</summary>
        Private m_lineHeight As Single
        ''' <summary>Characters contained in the font</summary>
        Private m_characters As List(Of VectorFontCharacter)
        ''' <summary>Look-up map for indices by unicode character</summary>
        Private m_characterMap As Dictionary(Of Char, Integer)
        ''' <summary>
        '''   Kerning table for adjusting the positions of specific character combinations
        ''' </summary>
        Private m_kerningTable As Dictionary(Of VectorFont.KerningPair, Vector2)

    End Class

End Namespace